import React, { useEffect, useState } from 'react'
import Header from './context/Header'
import Body from './context/body'
import '../../css/csy/context.css'
import { postFind } from '../../api/csy/api'
import { useLocation } from 'react-router-dom'


const Context = () => {

    useEffect(() => {
        const integralShop = sessionStorage.getItem('integralShop')
        if (integralShop) {
            if ((JSON.parse(integralShop).flag) === true) {
                sessionStorage.setItem('integralShop', JSON.stringify({ flag: false }))
                window.location.reload()
            }
        } else {
            sessionStorage.setItem('integralShop', JSON.stringify({ flag: true }))
        }
    }, [])

    const [list, setList] = useState([])

    const location = useLocation()

    const id = new URLSearchParams(location.search).get('id')

    const getdata = () => {
        postFind({ id: id }).then(res => {
            if (res.data.code == 200) {
                setList(res.data.data)
            }
        })
    }

    useEffect(() => {
        getdata()
    }, [])


    return (
        <>
            <div className='box'>
                <div className='context'>
                    <Header List={list}></Header>
                    {/* 绑定子传父的用发 */}
                    <Body getList={getdata} List={list}></Body>
                </div>
            </div>
        </>
    )
}

export default Context